﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DataAccess;
using System.Net.Http.Headers;
using System.IO;
using System.Runtime.InteropServices;

namespace Logic
{
    public class FS9901Logic
    {
        FS9901DataAccess fS9901DataAccess = new FS9901DataAccess();

        #region 获取需求图片的路径(相对路径)
        public string getRequirementImagePath(string strAutoID,string UrlRootPath)
        {
            DataTable dt = fS9901DataAccess.getRequirementImageData(strAutoID);
            if (dt!=null && dt.Rows.Count>0 && dt.Rows[0][0]!=null)
            {
                //图片路径
                string strImageName = Guid.NewGuid().ToString().Replace("-", "").ToUpper() + Path.GetExtension(dt.Rows[0]["vcRequirementPicName"].ToString());
                string strImagePath = Path.Combine(UrlRootPath, strImageName);
                string strImageUrl = "../../Doc/Temp/" + strImageName;

                byte[] imageByteData = (byte[])dt.Rows[0]["vcRequirementPic"];
                MemoryStream ms = new MemoryStream(imageByteData);
                System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                string strDir = Path.GetDirectoryName(strImagePath);
                if (!Directory.Exists(strDir)) Directory.CreateDirectory(strDir);
                img.Save(strImagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                return strImageUrl;
            }
            else
            {
                return "";
            }
        }
        #endregion
    }
}
